package com.gaohe.official.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gaohe.common.log.annotation.Log;
import com.gaohe.common.log.enums.BusinessType;
import com.gaohe.common.security.annotation.RequiresPermissions;
import com.gaohe.official.domain.FmTopic;
import com.gaohe.official.service.IFmTopicService;
import com.gaohe.common.core.web.controller.BaseController;
import com.gaohe.common.core.web.domain.AjaxResult;
import com.gaohe.common.core.utils.poi.ExcelUtil;
import com.gaohe.common.core.web.page.TableDataInfo;

/**
 * 系统栏目Controller
 * 
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/topic")
public class FmTopicController extends BaseController
{
    @Autowired
    private IFmTopicService fmTopicService;

    /**
     * 查询系统栏目列表
     */
    @RequiresPermissions("official:topic:list")
    @GetMapping("/list")
    public TableDataInfo list(FmTopic fmTopic)
    {
        startPage();
        List<FmTopic> list = fmTopicService.selectFmTopicList(fmTopic);
        return getDataTable(list);
    }

    /**
     * 导出系统栏目列表
     */
    @RequiresPermissions("official:topic:export")
    @Log(title = "系统栏目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmTopic fmTopic)
    {
        List<FmTopic> list = fmTopicService.selectFmTopicList(fmTopic);
        ExcelUtil<FmTopic> util = new ExcelUtil<FmTopic>(FmTopic.class);
        util.exportExcel(response, list, "系统栏目数据");
    }

    /**
     * 获取系统栏目详细信息
     */
    @RequiresPermissions("official:topic:query")
    @GetMapping(value = "/{topicId}")
    public AjaxResult getInfo(@PathVariable("topicId") Long topicId)
    {
        return success(fmTopicService.selectFmTopicByTopicId(topicId));
    }

    /**
     * 新增系统栏目
     */
    @RequiresPermissions("official:topic:add")
    @Log(title = "系统栏目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmTopic fmTopic)
    {
        return toAjax(fmTopicService.insertFmTopic(fmTopic));
    }

    /**
     * 修改系统栏目
     */
    @RequiresPermissions("official:topic:edit")
    @Log(title = "系统栏目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmTopic fmTopic)
    {
        return toAjax(fmTopicService.updateFmTopic(fmTopic));
    }

    /**
     * 删除系统栏目
     */
    @RequiresPermissions("official:topic:remove")
    @Log(title = "系统栏目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{topicIds}")
    public AjaxResult remove(@PathVariable Long[] topicIds)
    {
        return toAjax(fmTopicService.deleteFmTopicByTopicIds(topicIds));
    }
}
